//
//  ViewController.m
//  住房条件帅选器
//
//  Created by MB__Lee on 2018/5/15.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "ViewController.h"

#import "BaseListTableview.h"

#import "BaseHousePostModel.h"
#import "BaseHouseModel.h"
#import <MJRefresh.h>


#import "MBMutiSearchBar.h"
#import "BaseSearchView.h"
#import "OffBuildingSearchView.h"
#import "ShopSearchView.h"

#import <MJExtension.h>
#import "SearchViewFactory.h"


#define MBScreen_width [UIScreen mainScreen].bounds.size.width
#define MBScreen_height  [UIScreen mainScreen].bounds.size.height

@interface ViewController ()<BaseSearchViewDelegate>
#pragma mark ---房源列表相关
@property(nonatomic,strong)BaseListTableview *tableview;
@property(nonatomic,assign)NSInteger page;


@property(nonatomic,strong)BaseHousePostModel *model;
#pragma mark --通用
@property(nonatomic,strong)NSMutableArray *houseMut;//存放网络返回数据

#pragma mark ---最新封装的基类
@property(nonatomic,strong)BaseSearchView *baseSearch;

@end

@implementation ViewController




-(NSMutableArray *)houseMut{
    if (!_houseMut) {
        _houseMut =[NSMutableArray array];
    }
    return  _houseMut;
}


- (void)viewDidLoad {
    [super viewDidLoad];
   
//    [self.view addSubview:self.searBar];
//    [self.view addSubview:self.baseSearch];
   
    _model  =[[BaseHousePostModel alloc] init];
    
    
    [self Find_house];
    
    
    BaseSearchView *re = [SearchViewFactory creatSearViewWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, 50) searViewType:SearViewTypeOffBuiling];
    [self.view addSubview:re];
    re.delegate = self;
    
}

-(void)SearchView:(BaseSearchView *)searchView sendPostModel:(BaseHousePostModel *)model{
    
    [self.tableview deleteSource];
    
    model.city = MBCityCode;
    _model = model;
    
    [self getNetWithPage:0];
}




#pragma mark ---房源列表显示

-(void)Find_house{
    
    [self.view addSubview:self.tableview];
    __weak typeof(self)weakSelf = self;
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf getNetWithPage:1];
    }];
    [self.tableview.mj_header beginRefreshing];
    
    
    self.tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        _page += 1;
        [weakSelf getNetWithPage:_page];
    }];
}
-(BaseListTableview *)tableview{
    if (!_tableview) {
        _tableview = [[BaseListTableview alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 500) style:UITableViewStylePlain];
        
    }
    return  _tableview;
}

-(void)getNetWithPage:(NSInteger)page{
    _page = page;
    
//    BaseHousePostModel *postModel = [[BaseHousePostModel alloc] init];
//    postModel.category = @"1003";
//    postModel.city = @"103";
    _model.page = [NSString stringWithFormat:@"%zd",page];
//    postModel.rows = @"10";
    
    
    
    NSMutableDictionary *dict =  _model.mj_keyValues;
    
    NSLog(@"%@",dict);
    [MBNetTool MBPost:Fang_list paramater:dict success:^(id response) {
        
        NSMutableArray *mut = [BaseHouseModel mj_objectArrayWithKeyValuesArray:response[@"data"]];
        
        BaseHouseModel *model = mut.firstObject;
        
        NSLog(@"title----%@",model.title);
        [self.tableview addSource:mut];
        
        //        [self.tableview addSource:mut];
        NSLog(@"mut---%zd",self.houseMut.count);
        [self.tableview.mj_header endRefreshing];
        [self.tableview.mj_footer endRefreshing];
        
    } failure:^(NSError *error) {
        
    }];
    
}

#pragma mark --


@end
